from .models import *
from rest_framework import serializers
from user.models import User






class UserSimpleSerializers(serializers.ModelSerializer):

    class Meta:
        model = User
        fields = [
            'id',
            'username',
            'avatar'
            ]



class SubsReplySerializers(serializers.ModelSerializer):
    class Meta:
        model = Reply
        fields = [
            'id',
            'content',
            ' createtime',
            'useful_count',
            'unuseful_count',
            'user',
            ]

class ReplySerializers(serializers.ModelSerializer):
    subs = SubsReplySerializers(many=True)
    user = UserSimpleSerializers(many=True)
    class Meta:
        model = Reply
        fields = [
            'id',
            'content',
            'createtime',
            'useful_count',
            'problem',
            'unuseful_count',
            'subs',
            'user',
            'parent'

        ]




class QuestionSerializers(serializers.ModelSerializer):

    class Meta:
        model = Question

        fields = [
            'id',
            'createtime',
            'labels',
            'reply',
            'replyname',
            'title',
            'unuseful_count',
            'useful_count',
            'user',
            'visits',
            'content',
        ]

class QuestionSerializers_1(serializers.ModelSerializer):
    comment_question = ReplySerializers(many=True)
    class Meta:
        model = Question

        fields = [
            'id',
            'createtime',
            'labels',
            'reply',
            'replyname',
            'title',
            'unuseful_count',
            'useful_count',
            'user',
            'visits',
            'content',
            'comment_question',
        ]

class QuestionSerializers_2(serializers.ModelSerializer):
    answer_question = ReplySerializers(many=True)
    class Meta:
        model = Question

        fields = [
            'id',
            'createtime',
            'labels',
            'reply',
            'replyname',
            'title',
            'unuseful_count',
            'useful_count',
            'user',
            'visits',
            'content',
            'answer_question',
        ]


class QuestionSerializers_3(serializers.ModelSerializer):
    answer_comment_question = ReplySerializers(many=True)
    class Meta:
        model = Question

        fields = [
            'id',
            'createtime',
            'labels',
            'reply',
            'replyname',
            'title',
            'unuseful_count',
            'useful_count',
            'user',
            'visits',
            'content',
            'answer_comment_question',
        ]












